<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对象的增强与解构</title>
</head>

<body>

</body>
<script>

    const person = {
        // 键值对
        name: 'zhangsan', //属性
        age: 20,

        // 方法  es5 语法
        run: function () {
            console.log('zhangsan run')
        },

    }
    let height = 180
    const people = {
        height,//es6 语法
        //简写
        speak() {
            console.log('zhangsan speak')
        }
    }
    //es6 语法 ···扩展符
    obj = { name: 'zhangsan' }
    obj2 = {
        run() {
            console.log('zhangsan run')

        }
    }
    console.log({ ...obj, ...obj2 });
    //对象的解构
    //什么是解构
    //快速从对象容器中提取成员的一种方式
    const obj3 = {
        name: 'zhangsan',
        age: 20,
        gender: '男'
    }
    //es5
    var name = obj3.name
    var age = obj3.age
    var gender = obj3.gender
    console.log(name, age, gender)
    //es6
    let{age,name,gender}=obj3
    console.log(gender,name,age)
    //想要换名称，对象解构改属性方式用冒号
    let{age,name:newName,gender}=obj3
    console.log(newName,gender,age)


</script>

</html>